package com.xinsoft.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinsoft.constant.Const;
import com.xinsoft.entity.dto.CusDeviceDocumentPageParam;
import com.xinsoft.entity.po.CusDocument;
import com.xinsoft.entity.vo.CusDeviceFileVo;
import com.xinsoft.mapper.CusDocumentMapper;
import com.xinsoft.service.CusDocumentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author hsm
* @description 针对表【cus_document(设备文档表)】的数据库操作Service实现
* @createDate 2023-06-20 13:26:05
*/
@Service
public class CusDocumentServiceImpl extends ServiceImpl<CusDocumentMapper, CusDocument>
    implements CusDocumentService{

    @Override
    public CusDeviceFileVo getDocumentDetail(Integer id) {
        CusDeviceDocumentPageParam param = new CusDeviceDocumentPageParam();
        param.setId(id);
        List<CusDeviceFileVo> pageList = this.baseMapper.findListByParam(param);
        if(CollectionUtil.isEmpty(pageList)){
            return null;
        }
        return pageList.get(0);
    }

    @Override
    public void del(List<Integer> ids) {
        this.removeByIds(ids);
    }

    @Override
    public IPage<CusDeviceFileVo> findPageListByParam(CusDeviceDocumentPageParam param) {

        param.setDeviceRefType(Const.DeviceRefType.DEVICE_FILE);
        //分页
        Page<CusDeviceFileVo> page = new Page<>(param.getCurrentPage(), param.getPageSize());
        //查询分页
        IPage<CusDeviceFileVo> pageList = this.baseMapper.findListByParam(page, param);

        return pageList;
    }
}




